package com.site.wisdom_construction.controller.personnelModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.personnelModule.EducationTechnicalDisclosureRecordService;
import com.site.wisdom_construction.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/28
 * @Description
 */
@Api(tags = "安全技术交底记录接口")
@RestController
@RequestMapping("EducationTechnicalDisclosureRecord")
@CrossOrigin
public class EducationTechnicalDisclosureRecordController {
    @Autowired
    private EducationTechnicalDisclosureRecordService educationTechnicalDisclosureRecordService;

    @ApiOperation(value = "增加安全技术交底记录", notes = "测试数据:")
    @PostMapping("/insertEducationTechnicalDisclosureRecord")
    public JsonResult insertEducationTechnicalDisclosureRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationTechnicalDisclosureRecordService.insertEducationTechnicalDisclosureRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入安全技术交底记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入安全技术交底记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除安全技术交底记录", notes = "测试数据:")
    @PostMapping("/deleteEducationTechnicalDisclosureRecord")
    public JsonResult deleteEducationTechnicalDisclosureRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = educationTechnicalDisclosureRecordService.deleteEducationTechnicalDisclosureRecord(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除安全技术交底记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除安全技术交底记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改安全技术交底记录", notes = "测试数据:")
    @PostMapping("/updateEducationTechnicalDisclosureRecord")
    public JsonResult updateEducationTechnicalDisclosureRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationTechnicalDisclosureRecordService.updateEducationTechnicalDisclosureRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改安全技术交底记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改安全技术交底记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询安全技术交底记录", notes = "请求参数:pageNo,pageSize,projectId,模糊查询参数:workerName,workerCard,liabilityName")
    @PostMapping("/findEducationTechnicalDisclosureRecordByPage")
    public Page findEducationTechnicalDisclosureRecordByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(educationTechnicalDisclosureRecordService.Total(map));
        page.setItems(educationTechnicalDisclosureRecordService.findEducationTechnicalDisclosureRecordByPage(map));
        return page;
    }

    @ApiOperation(value = "根据id查询安全技术交底记录", notes = "请求参数:id")
    @PostMapping("/findEducationTechnicalDisclosureRecordById")
    public OneDataResult findEducationTechnicalDisclosureRecordById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationTechnicalDisclosureRecordService.findEducationTechnicalDisclosureRecordById(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据工人身份证号查询对应安全技术交底记录信息", notes = "请求参数:workerCard")
    @PostMapping("/findEducationTechnicalDisclosureRecordByWorkerCard")
    public OneDataResult findEducationTechnicalDisclosureRecordByWorkerCard(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationTechnicalDisclosureRecordService.findEducationTechnicalDisclosureRecordByWorkerCard(map));
        return oneDataResult;
    }

    @ApiOperation(value = "分页模糊查询教育负责人对应的安全技术交底记录", notes = "请求参数:pageNo,pageSize,projectId,managerialId,模糊查询参数:workerName,workerCard,liabilityName")
    @PostMapping("/findEducationTechnicalDisclosureRecordByManagerialId")
    public Page findEducationTechnicalDisclosureRecordByManagerialId(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(educationTechnicalDisclosureRecordService.TotalByManagerialId(map));
        page.setItems(educationTechnicalDisclosureRecordService.findEducationTechnicalDisclosureRecordByManagerialId(map));
        return page;
    }
}
